
package hz.mobileproject.pda.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.YiDianImpBean;
import hz.mobileproject.pda.listener.Send_end_Callroll_inter;
import hz.mobileproject.pda.utils.TimeMethod;


/**
 * Created by YOLANDA on 2016/7/22.
 */
public class YiDianImpBuWeiAdapter extends  RecyclerView.Adapter<YiDianImpBuWeiAdapter.ViewHolder> {


    public List<YiDianImpBean> datas = null;
    private Send_end_Callroll_inter callroll_inter;

//    public ImpBuWeiAdapter(List<Response_loadPrisonerList> datas, Send_end_Callroll_inter inter) {
//        this.datas = datas;
//        this.callroll_inter=inter;
//        this.onOff=false;
//    }

     public YiDianImpBuWeiAdapter(List<YiDianImpBean> data) {
         this.datas = data;
     }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_yidian_buwei,viewGroup,false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }
    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
//        viewHolder.mTextView.setText(datas[position]);
        viewHolder.tv_id.setText(String.valueOf(datas.get(position).check_id));
        viewHolder.tv_sum.setText(String.valueOf(datas.get(position).check_total));

        viewHolder.tv_time_start.setText(String.valueOf(TimeMethod.getTimeStrFromMillis(datas.get(position).start_time)));
        viewHolder.tv_end_time.setText(String.valueOf(TimeMethod.getTimeStrFromMillis(datas.get(position).end_time)));
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(impItemClickListener != null) {
                    impItemClickListener.OnImpItemClick(viewHolder.itemView,position);
                }
            }
        });



    }
    //获取数据的数量
    @Override
    public int getItemCount() {

//        LogUtils.e("datas.size():"+datas.size());

//            if (datas.size()==0&&!onOff){
//                callroll_inter.stace(0);
//                onOff=true;
//            }
        return datas==null?0:datas.size();
    }

    public void remove(YiDianImpBean bean) {
        datas.remove(bean);
        notifyDataSetChanged();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView tv_id;
        public TextView tv_sum;
        public TextView tv_time_start;
        public TextView tv_end_time;
        public ViewHolder(View view){
            super(view);
            tv_id = (TextView) view.findViewById(R.id.tv_id_si);
            tv_sum = (TextView) view.findViewById(R.id.tv_sum);
            tv_time_start = (TextView) view.findViewById(R.id.tv_time_start_si);
            tv_end_time = (TextView) view.findViewById(R.id.tv_time_end_si);
        }
    }




    public void addData(List<YiDianImpBean> datass) {
        datas.addAll(datass);
        notifyDataSetChanged();
    }

    private  OnImpItemClickListener impItemClickListener;

    public interface OnImpItemClickListener{
        void OnImpItemClick(View view, int position);
    }

    public void setImpItemClickListener(OnImpItemClickListener impItemClickListener) {
        this.impItemClickListener = impItemClickListener;
    }

}
